package com.itheima.comtroller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.pojo.Exercise;
import com.itheima.service.HeathService;
import com.itheima.utils.POIUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/health")
public class HeathController {
    @Reference
    private HeathService heathService;
    @RequestMapping("/serach")
    public List<Exercise> serach(String condition){
        System.out.println(condition);
        List<Exercise> exercises = heathService.find(condition);
        return exercises;
    }
    @RequestMapping("/upload")
    public List<Exercise> upload( @RequestBody MultipartFile multipartFile) throws IOException {
        System.out.println(multipartFile.getOriginalFilename());
        List<String[]> strings = POIUtils.readExcel(multipartFile);
        String result=null;
        for (String[] string : strings) {

            if( string[0].equals("病因")){
                result= string[1];
            }
            System.out.println(Arrays.toString(string));
        }
        List<Exercise> serach = heathService.find(result);
        System.out.println(serach.size());
        System.out.println(serach);

//        System.out.println(condition);
//        List<Exercise> exercises = heathService.find(condition);
        return serach;
    }
}
